package bb.lanxing.adapter.sport;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import bb.lanxing.R;
import bb.lanxing.calc.data.DisplayPoint;
import bb.lanxing.manager.SharedManager;
import bb.lanxing.mvp.view.sport.ItemStyle;
import bb.lanxing.utils.PanelItemTypeUtil;

public class SportActivityAdapter extends RecyclerView.Adapter<SportActivityAdapter.MyViewHolder> {
    private DisplayPoint mDisplayPoint;

    private List<Integer> mPanelItemTypeList;

    private Context mContext;

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_sport_new_item, parent, false);
        mContext = view.getContext();
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        if (mPanelItemTypeList == null) {
            return;
        }
        int itemType = mPanelItemTypeList.get(position + 1);
        holder.sport_item_digital.setText(PanelItemTypeUtil.getItemValue(mDisplayPoint, itemType));
        holder.sport_item_digital_unit.setText(PanelItemTypeUtil.getItemName(itemType));
        if (SharedManager.getInstance().isNightMode()) {
            holder.sport_item_digital.setTextColor(mContext.getColor(R.color.text_night));
            holder.sport_item_digital_unit.setTextColor(mContext.getColor(R.color.text_night));
        }
        ItemStyle itemStyle;
        if (SharedManager.getInstance().isBigFontMode()) {
            itemStyle = ItemStyle.ITEMS_BIG_FONT_STYLE[2][1];
        } else {
            itemStyle = ItemStyle.ITEMS_STYLE[2][1];
        }
        holder.sport_item_digital.setTextSize(itemStyle.textSize);
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    public void updateData(DisplayPoint displayPoint) {
        mDisplayPoint = displayPoint;
        notifyDataSetChanged();
    }

    public void updateItem(List<Integer> panelItemTypeList) {
        mPanelItemTypeList = panelItemTypeList;
        notifyDataSetChanged();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView sport_item_digital;
        public TextView sport_item_digital_unit;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            sport_item_digital = itemView.findViewById(R.id.sport_item_digital);
            sport_item_digital_unit = itemView.findViewById(R.id.sport_item_digital_unit);
        }
    }
}